package com.rem.hutool.my6JavaBean;

import cn.hutool.core.bean.BeanPath;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 获取 嵌套有很多层对象中深层次的值
 *
 * @author Rem
 * @date 2020-08-24
 */

public class BeanPathDemo {

    public static void main(String[] args) {
        ExamInfoDict examInfoDict = new ExamInfoDict(1, 0, 1);

        ExamInfoDict examInfoDict1 = new ExamInfoDict(2, 0, 0);

        ExamInfoDict examInfoDict2 = new ExamInfoDict(3, 1, 0);

        List<ExamInfoDict> examInfoDicts = Arrays.asList(examInfoDict, examInfoDict1, examInfoDict2);

//------------------------------------------------- 用户信息
        UserInfoDict userInfoDict = new UserInfoDict();
        userInfoDict.setId(1);
        userInfoDict.setPhotoPath("yx.mm.com");
        userInfoDict.setRealName("张三");
        userInfoDict.setExamInfoDict(examInfoDicts);

        //map集
        Map<String, Object> tempMap = new HashMap<>();
        tempMap.put("userInfo", userInfoDict);
        tempMap.put("flag", 1);
        System.err.println(tempMap);


        //获取map集 中深层次的值
        BeanPath resolver = new BeanPath("userInfo.examInfoDict[1].id");
        System.err.println(resolver.get(tempMap));
    }


    @AllArgsConstructor
    @NoArgsConstructor
    @Data
    static class ExamInfoDict {
        private Integer id;
        private Integer examType;
        private Integer answerIs;
    }

    @AllArgsConstructor
    @NoArgsConstructor
    @Data
    static class UserInfoDict {
        private Integer id;
        private String photoPath;
        private String realName;
        private List<ExamInfoDict> examInfoDict;
    }
}
